﻿using System;
using System.IO;

namespace Toybox.SCM.Models.Configs
{
	using Models.Windows;
	using NicoSharp.Abstracts;
	using NicoSharp.Utilities;


	public class UIConfig : AbstractNotifyObject
	{

		#region [Static]

		/// <summary>
		/// ファイルからUI設定を読み込む
		/// </summary>
		/// <returns></returns>
		public static UIConfig Load(string path)
		{
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Open))
				{
					return Deserializer.XmlDeserializer<UIConfig>(fs);
				}
			}
			catch (Exception ex)
			{
				return new UIConfig();
			}
		}

		/// <summary>
		/// ファイルへUI設定を書き込む
		/// </summary>
		/// <returns></returns>
		public static void Save(string path, UIConfig config)
		{
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Create))
				{
					Serializer.XmlSerializer<UIConfig>(fs, config);
				}
			}
			catch (Exception ex)
			{
			}
		}

		#endregion [Static]


		#region Constructor

		/// <summary>
		/// コンストラクタ
		/// </summary>
		public UIConfig()
		{
			// デフォルト値
			this.MainConfig = new MainWindowConfig();
			this.EditConfig = new EditWindowConfig();
			this.ConfigConfig = new ConfigWindowConfig();
		}

		#endregion Constructor


		#region Public Members

		public MainWindowConfig MainConfig
		{
			get { return this._mainConfig; }
			set
			{
				if (this._mainConfig == value) return;
				this._mainConfig = value;
				base.OnPropertyChanged("MainConfig");
			}
		}
		private MainWindowConfig _mainConfig;

		public EditWindowConfig EditConfig
		{
			get { return this._editConfig; }
			set
			{
				if (this._editConfig == value) return;
				this._editConfig = value;
				base.OnPropertyChanged("EditConfig");
			}
		}
		private EditWindowConfig _editConfig;

		public ConfigWindowConfig ConfigConfig
		{
			get { return this._configConfig; }
			set
			{
				if (this._configConfig == value) return;
				this._configConfig = value;
				base.OnPropertyChanged("ConfigConfig");
			}
		}
		private ConfigWindowConfig _configConfig;

		#endregion Public Members

	}
}
